package com.ren.scale.controller.front;

import com.ren.scale.constant.CachePrefix;
import com.ren.scale.entity.ReclScaleOrder;
import com.ren.scale.service.ReclScaleOrderService;
import com.ren.utils.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: ReclScaleFrontOrderController
 * @Description: TODO
 * @Author: RZY
 * @DATE: 2022/7/18 18:31
 * @Version: v1.0
 */

@Api(tags = "量表前台订单接口")
@RestController
@RequestMapping("/recl-scale/front/order")
public class ReclScaleFrontOrderController {

    @Autowired
    ReclScaleOrderService scaleOrderService;


    @ApiOperation(value = "确认量表订单信息")
    @GetMapping("/{userId}/{scaleId}")
    public R getFrontScaleOrderInfo(@PathVariable Long userId, @PathVariable Long scaleId) {
        ReclScaleOrder scaleOrder = scaleOrderService.getFrontScaleOrder(userId, scaleId);
        return R.ok()
                .data("scaleOrder", scaleOrder);
    }

    @ApiOperation(value = "提交量表订单")
    @PostMapping("")
    public R submitScaleOrder(@RequestBody ReclScaleOrder scaleOrder) {

        //提交订单
        boolean res = scaleOrderService.submitScaleOrder(scaleOrder);
        //判断下单结果
        if(res) return R.ok()
                .message("订单提交成功!");
        else return R.error()
                .message("订单提交失败，请稍后重试!");
    }
}
